package com.yc.hotel.feign.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yc.hotel.dto.RoomInfoDTO;
import com.yc.hotel.dto.UserInfoDTO;

import com.yc.hotel.service.IRoomInfoService;
import com.yc.hotel.user.feign.IUserInfoFeignClient;


@RestController
@RequestMapping("/rooms")
public class RoomInfoClientController {

	@Autowired
	private IRoomInfoService roomInfoServiceImpl;
	
	@Autowired
	private IUserInfoFeignClient userInfoFeignController;
	
	
	@PostMapping("/findByRno")
	RoomInfoDTO findByRno(@RequestParam int rno) {
		RoomInfoDTO room = roomInfoServiceImpl.findByRno(rno);
		int uno = room.getUno();
		UserInfoDTO user = userInfoFeignController.findByUno(uno);
		room.setNickName(user.getNickName());
		room.setTel(user.getTel());
		return room;
	};
	
	@PostMapping("/updateStatus")
	int updateStatus(@RequestParam Map<String, Object> map) {
		int result = roomInfoServiceImpl.updateStatus(map);
		return result;
	};
	
	@PostMapping("/endSale")
	int endSale(@RequestBody RoomInfoDTO room) {
		
		int result = roomInfoServiceImpl.endSale(room);
		return result;
	};
	
	@PostMapping("/finds")
	List<RoomInfoDTO> finds(@RequestParam Map<String, Object> map) {
		
		List<RoomInfoDTO> list = roomInfoServiceImpl.findsF(map);
		System.out.println("finds:" +list);
		for(RoomInfoDTO room : list) {
			int uno = room.getUno();
			UserInfoDTO user = userInfoFeignController.findByUno(uno);
			room.setNickName(user.getNickName());
			room.setTel(user.getTel());
		}
		return list;
	};
	
	@PostMapping("/add")
	int add(@RequestBody RoomInfoDTO room) {
		int result = roomInfoServiceImpl.addF(room);
		return result;
	};

}
